package com.ibm.interfaces;

import java.util.Collection;
import java.util.HashSet;
import java.util.List;

import com.fasterxml.jackson.databind.node.ObjectNode;
import com.ibm.util.exception.CPSException;

/**
 * @author Yaoliang Chen
 * @version May 26, 2014 Description
 */

public interface INoSqlDB {
	/**
	 * initialize the connection of the database TODO add user and password
	 * 
	 * @param hostname
	 * @param port
	 * @param dbName
	 * @return
	 */
	public abstract void init(String hostname, int port, String dbName)
			throws CPSException;

	/**
	 * initialize the connection of the database 
	 * @param uri
	 * @param dbName
	 * @throws CPSException
	 */
	public abstract void init(String uri, String dbName) throws CPSException;

	/**
	 * get the collection id of the given collection name
	 * 
	 * @param name
	 * @return >=0
	 */
	public abstract int getCollection(String name) throws CPSException;

	public abstract Object getDB();

	public abstract Object getCollection(int collection) throws CPSException;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.WhaleDB.tools.mongo.INoSqlDB#insert(int, org.json.ObjectNode)
	 */
	public abstract void insert(int colid, ObjectNode json, String keyTag,
			HashSet<String> tags) throws CPSException;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.WhaleDB.tools.mongo.INoSqlDB#findOne(int, java.lang.Object)
	 */
	public abstract ObjectNode findOne(int collid, Object _id, String keyTag)
			throws CPSException;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.WhaleDB.tools.mongo.INoSqlDB#find(int, org.json.ObjectNode)
	 */
	public abstract IResultCursor<ObjectNode> find(int collid,
			ObjectNode filter, boolean onlyKey, String tagName)
			throws CPSException;

	public abstract int update(int collid, ObjectNode doc, String keyTag,
			HashSet<String> tags) throws CPSException;

	public abstract int delete(int collid, Object key) throws CPSException;

	public abstract void dropDatabase() throws CPSException;

	public abstract void bulkInsert(int colid, List<ObjectNode> jsons,
			String keyTag, HashSet<String> tags) throws CPSException;

	public abstract void flush() throws CPSException;

	void upsert(int colid, ObjectNode json, String keyTag, HashSet<String> tags)
			throws CPSException;

	void createIndex(int colid, String indexTag) throws CPSException;

	void createUniqueIndex(int colid, String indexTag) throws CPSException;

	void createIndex(int colid, String[] indexTag) throws CPSException;

	public abstract void deleteCollections(Collection<String> collection);
	
	public abstract void close() throws CPSException;

}
